function getQueryString(params) {
  let url = location.href;
  let reg = /(?<=\?).*/;
  let r = url.match(reg);
  // console.log(r)
  if (!r) {
    console.error("没有匹配到url参数");
    return;
  } else {
    r = decodeURI(r[0]);
    // console.log(r)
    if (params) {
      let result = r.indexOf(params);
      if (result === -1) {
        return null;
      }
      let queryArr = r.split("&");
      let obj = {};
      queryArr.forEach((item) => {
        let itemArr = item.split("=");
        obj[itemArr[0]] = itemArr[1];
      });
      return obj[params];
    } else {
      return null;
    }
  }
}
let id = getQueryString("id");
let ul = document.querySelector("ul");
let el = "";
document.onreadystatechange = function () {
  if (document.readyState === "interactive") {
    fetch(`http://chst.vip:1234/api/getdiscountproduct?productid=${id}`)
      .then((body) => body.json())
      .then((res) => {
        res.result.forEach((item) => {
          // let regExp = /(?<=imgurl=)[^'"]*/
          // let url = item.productImg2.match(regExp)
          el += ` <li>
    <h4>${item.productName}</h4>
    <span>${item.productFrom}|${item.productTime}</span>
    <i>${item.productTips}</i>
    ${item.productImg}
    <p>${item.productInfo}</p>
    <button>前往购买</button>
    <img src=""/>
    <input type="text" value="说说你的想法呀"/>
    <button>提交评论</button>
</li>`;
        });
        ul.innerHTML = el;
      });
  }
};
